package cn.dckeji.dcssm.service.impl;

import cn.dckeji.dcssm.common.utils.JedisUtil;
import cn.dckeji.dcssm.common.utils.MD5Util;
import cn.dckeji.dcssm.entity.Park;
import cn.dckeji.dcssm.dao.ParkDao;
import cn.dckeji.dcssm.entity.Users;
import cn.dckeji.dcssm.service.ParkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Kenny
 * @since 2019-08-01
 */
@Service
public class ParkServiceImpl extends ServiceImpl<ParkDao, Park> implements ParkService {

   @Resource
   private  ParkDao parkDao;


    @Override
    public boolean savePark(Park park,String parkNos) {
        //查询登录名重复没
        String parkNo = park.getParkNo();
        Park users1 = parkDao.selectOne(new QueryWrapper<Park>().eq("parkNo", parkNo).eq("deleteFlag",0));
        if (users1!=null) {
            if (StringUtils.isNotBlank(park.getParkId())) {
                String dataAdminId = users1.getParkId();
                if (dataAdminId.equals(park.getParkId())) {
                    JedisUtil.del(users1.getParkNo().toString());
                    JedisUtil.set(parkNo.toString(), "", 0);
                    users1.setParkNo(parkNo);
                    users1.setParkPrice(park.getParkPrice());
                    parkDao.updateById(users1);
                    return true;
                }
            }
        }else {
            if (StringUtils.isNotBlank(park.getParkId())) {
                JedisUtil.del(parkNos.toString());
                JedisUtil.set(park.getParkNo(), "", 0);
                parkDao.updateById(park);
            }else {
                park.setGmtCreate(LocalDateTime.now());
                JedisUtil.set(park.getParkNo(), "", 0);
                parkDao.insert(park);
            }
            return true;
        }
        return false;
    }
}
